using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using JYJ.AiYard.Configuration;
using JYJ.AiYard.Helpers;

namespace JYJ.AiYard.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class AiYardDbContextFactory : IDesignTimeDbContextFactory<AiYardDbContext>
    {
        public AiYardDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<AiYardDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            AiYardDbContextConfigurer.Configure(builder,
                configuration.GetConnectionString(AppConsts.ConnectionStringName));

            return new AiYardDbContext(builder.Options);
        }
    }
}